int classwise(unsigned char* ip) {
    unsigned char first_byte = ip[0];
    if (first_byte <= 127) {
        return 0;
    }
    else if (first_byte <= 191) {
        return 1;
    }
    else if (first_byte <= 223) {
        return 2;
    }
    else if (first_byte <= 239) {
        return 3;
    }
    else {
        return 4;
    }
}